home *** CD-ROM | disk | FTP | other *** search
- // This code was written Thursday June 22, 1992 by Jorg 'jbx' Brown.
- // This code is not freeware; this code is public domain.
-
- // Written in Think C 5.0. Anything less would be unthinkable.
-
- #undef SystemSevenOrLater
- #define SystemSevenOrLater 1
-
- #include "Misc.h"
- #include <GestaltEqu.h>
- #include <PPCToolbox.h>
- #include <EPPC.h>
- #include <AppleEvents.h>
- #include <Retrace.h>
-
- static void pJGNEFilter(void);
-
- static short PPC_waiting = 1;
- static short call_inform = 0;
- static char buffer[512];
- static short new_mouse;
- short whichReader = 1;
- PPCReadPBRec Reader1, Reader2;
-
- static void pJGNEFilter(void);
-
- long oldPostEvent, oldButton;
- static void pPostEvent(void);
- static void pButton(void);
-
- void main(void) {
- short i, j;
- SetA4(&main);
- asm {
- lea @pj+2,a0
- move.l JGNEFilter,(a0)
- bne.s @nrm
- move.w #0x4E75,-2(a0)
- nrm: lea @ptch,a0
- move.l a0,JGNEFilter
- };
-
- oldPostEvent = GetOSTrapAddress(0xA12F);
- SetOSTrapAddress((long) &pPostEvent, 0xA12F);
-
- oldButton = GetToolTrapAddress(0xA974);
- SetToolTrapAddress((long) &pButton, 0xA974);
-
- DetachResource(RecoverHandle(&main));
-
- for (i = 1000; i < 1006; i++) {
- ShowINIT(0, i);
- jbxDelay(15);
- }
- ShowINIT(1006, 0);
-
- for (i = 2000; i < 2004; i++) {
- ShowINIT(0, i);
- jbxDelay(15);
- }
- ShowINIT(2004, 0);
-
- return;
-
- if (0) asm { /* let's not execute the patch code, shall we? */
- ptch: cmpi.w #nullEvent,OFFSET(EventRecord, what)(a1)
- bne @pj
- movem.l a0-a1/a4/d0-d2,-(a7)
- lea main,a4
- move.l a1,-(a7)
- jsr pJGNEFilter
- addq #4,a7
- movem.l (a7)+,a0-a1/a4/d0-d2
- cmpi.w #nullEvent,OFFSET(EventRecord, what)(a1)
- beq.s @pj
- moveq #1,d0
- move.w d0,4(a7)
- pj: jmp 0x12345678
- }
- }
-
- extern Point Mouse : 0x830;
- extern char MBState : 0x172;
- extern char CrsrBusy : 0x8CD;
-
- static
- short qRelString(void *first, void *second) {
- asm {
- moveq #-1, d0
- move.l first,a0
- move.l second,a1
-
- move.b 1(a0),d1
- cmpi.b #'a',d1
- blt.s @1
- cmpi.b #'z',d1
- bgt.s @1
- add.b #'A'-'a',d1
- @1
- move.b 1(a1),d2
- cmpi.b #'a',d2
- blt.s @2
- cmpi.b #'z',d2
- bgt.s @2
- add.b #'A'-'a',d2
- @2
- cmp.b d2,d1
- beq.s @comp
- blo.s @out
- moveq #1,d0
- bra.s @out
- comp: moveq #0,d0
- move.b (a0)+,d0
- swap d0
- move.b (a1)+,d0
- RelString
- out:;
- }
- }
-
- short foo;
-
- static
- pascal Boolean myFilterProc(LocationNamePtr LNP, PortInfoPtr PIP) {
- short result = FALSE;
- asm {
- move.l a4,-(a7)
- lea main,a4
- }
- if (PIP->name.portKindSelector == ppcByString) {
- if (qRelString(PIP->name.u.portTypeStr, "\pMac Hax") == 0) {
- result = TRUE;
- }
- }
- asm {
- move.l (a7)+,a4
- }
- return result;
- }
-
- static short broadcast;
- static PPCOpenPBRec PPCOpenRec;
- static PPCPortRec PPCPort;
- static LocationNameRec LNR;
- static PortInfoRec PIR;
-
- PPCWritePBRec Writer;
-
- PPCStartPBRec start;
-
- static
- short setup(void) {
- short i;
-
- LNR.locationKindSelector = ppcNBPLocation;
- PStringMove("\pMoof", LNR.u.nbpEntity.objStr);
- PStringMove("\p=", LNR.u.nbpEntity.zoneStr);
-
- PIR.authRequired = FALSE;
- PIR.name.nameScript = 0; // smRoman;
- PStringMove("\pInside Macintosh", PIR.name.name);
- PIR.name.portKindSelector = ppcByString;
- PStringMove("\pExample", PIR.name.u.portTypeStr);
-
- if (PPCBrowser("\pPrompt", "\pMice", FALSE, &LNR, &PIR, &myFilterProc, "\p") != noErr) return -1;
-
- ////////////////////////
-
- PPCPort.nameScript = 0; // smRoman;
- PStringMove("\pKennedy Mouse", PPCPort.name);
- PPCPort.portKindSelector = ppcByString;
- PStringMove("\pKennedy Hax", PPCPort.u.portTypeStr);
-
- PPCOpenRec.ioCompletion = 0;
- PPCOpenRec.serviceType = ppcServiceRealTime;
- PPCOpenRec.resFlag = 0;
- PPCOpenRec.portName = &PPCPort;
- PPCOpenRec.locationName = 0;
- PPCOpenRec.networkVisible = false;
- if (PPCOpenSync(&PPCOpenRec) == noErr) {
- start.ioCompletion = 0;
- start.portRefNum = PPCOpenRec.portRefNum;
- start.serviceType = ppcServiceRealTime;
- start.resFlag = FALSE;
- start.portName = &PIR.name; // PPCPortRec *
- start.locationName = &LNR;
- start.userData = 'jbx!';
- start.userRefNum = 0;
- if (PPCStartSync(&start) == noErr) {
- return 0;
- } else {
- return -1;
- }
- PPCCloseSync((void *)&PPCOpenRec);
- } else {
- return -1;
- }
- }
-
- EventRecord myEvent;
- struct {
- Point ms;
- short down;
- } MouseData, lastMD;
- short lastButton;
-
- VBLTask InterruptDude = {
- 0,
- vType,
- 0,
- 2,
- 0
- };
-
- PPCWritePBRec vWriter;
-
- static short needShow, needHide;
-
- static void myTask(void) {
- void *oldA4 = SetA4(&main);
-
- InterruptDude.vblCount = 2;
-
- if (vWriter.ioResult <= 0) {
- MouseData.ms = Mouse;
- MouseData.down = MBState;
- if (broadcast) {
- if (MouseData.ms.h == 0 && MouseData.ms.v < 20) {
- broadcast = 0;
- MouseData.ms.h = CrsrPin.right - 10;
- *(Point *)0x828 = MouseData.ms;
- *(Point *)0x82C = MouseData.ms;
- *(Point *)0x830 = MouseData.ms;
- needShow = 1;
- } else if (MouseData.ms.h >= CrsrPin.right - 1 && MouseData.ms.v < 20) {
- broadcast = 0;
- MouseData.ms.h = 10;
- *(Point *)0x828 = MouseData.ms;
- *(Point *)0x82C = MouseData.ms;
- *(Point *)0x830 = MouseData.ms;
- needShow = 1;
- } else {
- if (lastMD.ms.h != MouseData.ms.h ||
- lastMD.ms.v != MouseData.ms.v ||
- lastMD.down != MouseData.down) {
- vWriter.ioCompletion = 0;
- vWriter.sessRefNum = start.sessRefNum;
- vWriter.more = FALSE;
- vWriter.userData = 0;
- vWriter.blockCreator = 'crea';
- vWriter.blockType = 'type';
- vWriter.bufferLength = 6;
- vWriter.bufferPtr = (void *)&MouseData;
- PPCWriteAsync(&vWriter);
- lastMD = MouseData;
- }
- }
- } else {
- if (MouseData.ms.v < 20) {
- if (MouseData.ms.h < 1) {
- broadcast = 1;
- MouseData.ms.h = CrsrPin.right - 10;;
- *(Point *)0x828 = MouseData.ms;
- *(Point *)0x82C = MouseData.ms;
- *(Point *)0x830 = MouseData.ms;
- needHide = 1;
- } else if (MouseData.ms.h >= CrsrPin.right - 1) {
- broadcast = 1;
- MouseData.ms.h = 10;
- *(Point *)0x828 = MouseData.ms;
- *(Point *)0x82C = MouseData.ms;
- *(Point *)0x830 = MouseData.ms;
- needHide = 1;
- }
- }
- }
- }
-
- InterruptDude.vblCount = 2;
-
- SetA4(oldA4);
- }
-
- static void pJGNEFilter(void) {
- static short recursion;
- long PPC_flags;
-
- GrafPtr oldPortPtr;
-
- if (recursion) return;
- if (PPC_waiting < 0) return;
- if (PPC_waiting == 1) {
- if (Gestalt(gestaltPPCToolboxAttr, &PPC_flags) != noErr) return;
- if (!(PPC_flags & gestaltPPCSupportsRealTime)) return;
- recursion = 1;
- PPC_waiting = setup();
- if (PPC_waiting == 0) {
- InterruptDude.vblAddr = (void *)&myTask;
- VInstall((void *)&InterruptDude);
- }
- recursion = 0;
- return;
- }
- if (needShow) {
- needShow = 0;
- ShowCursor();
- }
- if (needHide) {
- needHide = 0;
- HideCursor();
- }
- }
-
- static
- void GetTheEvent(void) {
- EventRecord myEvent;
- if (GetOSEvent(mDownMask + mUpMask + keyDownMask, &myEvent)) {
- Writer.ioCompletion = 0;
- Writer.sessRefNum = start.sessRefNum;
- Writer.more = FALSE;
- Writer.userData = 0;
- Writer.blockCreator = 'crea';
- Writer.blockType = 'type';
- Writer.bufferLength = sizeof(myEvent);
- Writer.bufferPtr = (void *)&myEvent;
- PPCWriteAsync(&Writer);
- // while (Writer.ioResult > 0);
- }
- }
-
- void pPostEvent(void) {
- asm {
- subq #4,a7
- move.l a4,-(a7)
- lea main,a4
- move.l oldPostEvent,4(a7)
- tst.w broadcast
- beq.s @out
- pea @ovr
- move.l oldPostEvent,-(a7)
- rts
- ovr: movem.l d0/d1/d2/a0/a1,-(a7)
- jsr GetTheEvent
- movem.l (a7)+,d0/d1/d2/a0/a1
- move.l (a7)+,a4
- addq #4,a7
- rts
- out: move.l (a7)+,a4
- }
- }
-
- void pButton(void) {
- asm {
- subq #4,a7
- move.l a4,-(a7)
- lea main,a4
- move.l oldButton,4(a7)
- tst.w broadcast
- beq.s @dn
- move.l (a7)+,a4
- addq #4,a7
- clr.w 4(a7)
- rts
- dn: move.l (a7)+,a4
- }
- }